#!/bin/sh -efu
### This file is covered by the GNU General Public License,
### which should be included with libshell as the file LICENSE.
### All copyright information are listed in the COPYING.

if [ -z "${__included_shell_temp-}" ]; then
__included_shell_temp=1

. shell-error
. shell-signal

__shell_clean_temp=0
__shell_clean_temp()
{
	local i=0 temp=
	while [ $i -lt ${__shell_clean_temp:-0} ]; do
		eval "temp=\"\$__shell_clean_temp_$i\""
		rm $verbose -rf -- "$temp"
		i=$(($i + 1))
	done
}

### Usage: create_temporary ret [mktemp options]
create_temporary()
{
	local __create_temporary_out __create_temporary_var="$1"
	shift
	[ "$#" != 0 ] || set -- -dt
	__create_temporary_out="$(mktemp "$@" "$PROG.XXXXXXXXX")"
	eval "__shell_clean_temp_$__shell_clean_temp=\"\$__create_temporary_out\""
	[ "$__shell_clean_temp" != 0 ] ||
		signal_handler __shell_clean_temp EXIT HUP PIPE INT QUIT TERM
	__shell_clean_temp=$(($__shell_clean_temp + 1))
	eval "$__create_temporary_var=\"\$__create_temporary_out\""
}

fi #__included_shell_temp
